package br.com.fiaproupas.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.fiaproupas.model.Usuario;
import br.com.fiaproupas.util.RetornaJson;
import br.com.fiaproupas.util.RetornaLista;

/**
 * Servlet implementation class ListaUsuariosServlet
 */
@WebServlet("/listaUsuariosServlet")
public class ListaUsuariosServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ListaUsuariosServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RetornaJson retornaJson = new RetornaJson();
		String usuarioS = retornaJson.retornaJsonUsuarios();
		
		RetornaLista retornaLista = new RetornaLista();
		List<Usuario> usuarios = retornaLista.buscaUsuarios(usuarioS);
		
	    request.getSession().setAttribute("usuarios", usuarios);
	    
	    request.getRequestDispatcher("listausuarios.jsp").forward(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
	}
}
